Loading...
Searching...
No Matches
rapidjson::GenericDocument< Encoding, Allocator, StackAllocator > Class Template Reference

A document for parsing JSON text as DOM. More...

#include <document.h>

Inheritance diagram for rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >:
rapidjson::GenericValue< Encoding, RAPIDJSON_DEFAULT_ALLOCATOR >

Public Types

typedef Encoding::Ch Ch
 Character type derived from Encoding.
typedef GenericValue< Encoding, AllocatorValueType
 Value type of the document.
typedef Allocator AllocatorType
 Allocator type from template parameter.
typedef StackAllocator StackAllocatorType
 StackAllocator type from template parameter.
Public Types inherited from rapidjson::GenericValue< Encoding, RAPIDJSON_DEFAULT_ALLOCATOR >
typedef GenericMember< Encoding, RAPIDJSON_DEFAULT_ALLOCATORMember
 Name-value pair in an object.
typedef Encoding EncodingType
 Encoding type from template parameter.
typedef RAPIDJSON_DEFAULT_ALLOCATOR AllocatorType
 Allocator type from template parameter.
typedef Encoding::Ch Ch
 Character type derived from Encoding.
typedef GenericStringRef< ChStringRefType
 Reference to a constant string.
typedef GenericMemberIterator< false, Encoding, RAPIDJSON_DEFAULT_ALLOCATOR >::Iterator MemberIterator
 Member iterator for iterating in object.
typedef GenericMemberIterator< true, Encoding, RAPIDJSON_DEFAULT_ALLOCATOR >::Iterator ConstMemberIterator
 Constant member iterator for iterating in object.
typedef GenericValueValueIterator
 Value iterator for iterating in array.
typedef const GenericValueConstValueIterator
 Constant value iterator for iterating in array.
typedef GenericValue< Encoding, RAPIDJSON_DEFAULT_ALLOCATORValueType
 Value type of itself.
typedef GenericArray< false, ValueTypeArray
typedef GenericArray< true, ValueTypeConstArray
typedef GenericObject< false, ValueTypeObject
typedef GenericObject< true, ValueTypeConstObject

Public Member Functions

 GenericDocument (Type type, Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
 Constructor.
 GenericDocument (Allocator *allocator=0, size_t stackCapacity=kDefaultStackCapacity, StackAllocator *stackAllocator=0)
 Constructor.
GenericDocumentSwap (GenericDocument &rhs) RAPIDJSON_NOEXCEPT
 Exchange the contents of this document with those of another.
template<typename Generator>
GenericDocumentPopulate (Generator &g)
 Populate this document by a generator which produces SAX events.
AllocatorGetAllocator ()
 Get the allocator of this document.
size_t GetStackCapacity () const
 Get the capacity of stack in bytes.
bool Null ()
bool Bool (bool b)
bool Int (int i)
bool Uint (unsigned i)
bool Int64 (int64_t i)
bool Uint64 (uint64_t i)
bool Double (double d)
bool RawNumber (const Ch *str, SizeType length, bool copy)
bool String (const Ch *str, SizeType length, bool copy)
bool StartObject ()
bool Key (const Ch *str, SizeType length, bool copy)
bool EndObject (SizeType memberCount)
bool StartArray ()
bool EndArray (SizeType elementCount)
GenericValueSwap (GenericValue &other) RAPIDJSON_NOEXCEPT
 Exchange the contents of this value with those of other.
Parse from stream
template<unsigned parseFlags, typename SourceEncoding, typename InputStream>
GenericDocumentParseStream (InputStream &is)
 Parse JSON text from an input stream (with Encoding conversion)
template<unsigned parseFlags, typename InputStream>
GenericDocumentParseStream (InputStream &is)
 Parse JSON text from an input stream.
template<typename InputStream>
GenericDocumentParseStream (InputStream &is)
 Parse JSON text from an input stream (with kParseDefaultFlags)
Parse in-place from mutable string
template<unsigned parseFlags>
GenericDocumentParseInsitu (Ch *str)
 Parse JSON text from a mutable string.
GenericDocumentParseInsitu (Ch *str)
 Parse JSON text from a mutable string (with kParseDefaultFlags)
Parse from read-only string
template<unsigned parseFlags, typename SourceEncoding>
GenericDocumentParse (const typename SourceEncoding::Ch *str)
 Parse JSON text from a read-only string (with Encoding conversion)
template<unsigned parseFlags>
GenericDocumentParse (const Ch *str)
 Parse JSON text from a read-only string.
GenericDocumentParse (const Ch *str)
 Parse JSON text from a read-only string (with kParseDefaultFlags)
template<unsigned parseFlags, typename SourceEncoding>
GenericDocumentParse (const typename SourceEncoding::Ch *str, size_t length)
template<unsigned parseFlags>
GenericDocumentParse (const Ch *str, size_t length)
GenericDocumentParse (const Ch *str, size_t length)
Handling parse errors
bool HasParseError () const
 Whether a parse error has occurred in the last parsing.
ParseErrorCode GetParseError () const
 Get the ParseErrorCode of last parsing.
size_t GetErrorOffset () const
 Get the position of last parsing error in input, 0 otherwise.
 operator ParseResult () const
 Implicit conversion to get the last parse result.
Public Member Functions inherited from rapidjson::GenericValue< Encoding, RAPIDJSON_DEFAULT_ALLOCATOR >
 ~GenericValue ()
 Destructor.
bool operator== (const GenericValue< Encoding, SourceAllocator > &rhs) const
 Equal-to operator.
bool operator!= (const GenericValue< Encoding, SourceAllocator > &rhs) const
 Not-equal-to operator.
Type GetType () const
bool IsNull () const
bool IsFalse () const
bool IsTrue () const
bool IsBool () const
bool IsObject () const
bool IsArray () const
bool IsNumber () const
bool IsInt () const
bool IsUint () const
bool IsInt64 () const
bool IsUint64 () const
bool IsDouble () const
bool IsString () const
bool IsLosslessDouble () const
bool IsFloat () const
bool IsLosslessFloat () const
GenericValueSetNull ()
bool GetBool () const
 Set boolean value.
GenericValueSetBool (bool b)
GenericValueSetObject ()
 Set this value as an empty object.
SizeType MemberCount () const
 Get the number of members in the object.
SizeType MemberCapacity () const
 Get the capacity of object.
bool ObjectEmpty () const
 Check whether the object is empty.
GenericValueoperator[] (T *name)
 Get a value from an object associated with the name.
ConstMemberIterator MemberBegin () const
 Const member iterator.
ConstMemberIterator MemberEnd () const
 Const past-the-end member iterator.
GenericValueMemberReserve (SizeType newCapacity, RAPIDJSON_DEFAULT_ALLOCATOR &allocator)
 Request the object to have enough capacity to store members.
bool HasMember (const Ch *name) const
 Check whether a member exists in the object.
MemberIterator FindMember (const Ch *name)
 Find member by name.
GenericValueAddMember (GenericValue &name, GenericValue &value, RAPIDJSON_DEFAULT_ALLOCATOR &allocator)
 Add a member (name-value pair) to the object.
void RemoveAllMembers ()
 Remove all members in the object.
bool RemoveMember (const Ch *name)
 Remove a member in object by its name.
MemberIterator EraseMember (ConstMemberIterator pos)
 Remove a member from an object by iterator.
Object GetObject ()
Object GetObj ()
int GetInt () const
unsigned GetUint () const
int64_t GetInt64 () const
uint64_t GetUint64 () const
double GetDouble () const
 Get the value as double type.
float GetFloat () const
 Get the value as float type.
GenericValueSetInt (int i)
GenericValueSetUint (unsigned u)
GenericValueSetInt64 (int64_t i64)
GenericValueSetUint64 (uint64_t u64)
GenericValueSetDouble (double d)
GenericValueSetFloat (float f)
const ChGetString () const
SizeType GetStringLength () const
 Get the length of string.
GenericValueSetString (const Ch *s, SizeType length)
 Set this value as a string without copying source string.
GenericValueSetArray ()
 Set this value as an empty array.
SizeType Size () const
 Get the number of elements in array.
SizeType Capacity () const
 Get the capacity of array.
bool Empty () const
 Check whether the array is empty.
void Clear ()
 Remove all elements in the array.
ValueIterator Begin ()
 Element iterator.
ValueIterator End ()
 Past-the-end element iterator
GenericValueReserve (SizeType newCapacity, RAPIDJSON_DEFAULT_ALLOCATOR &allocator)
 Request the array to have enough capacity to store elements.
GenericValuePushBack (GenericValue &value, RAPIDJSON_DEFAULT_ALLOCATOR &allocator)
 Append a GenericValue at the end of the array.
GenericValuePopBack ()
 Remove the last element in the array.
ValueIterator Erase (ConstValueIterator pos)
 Remove an element of array by iterator.
Array GetArray ()
bool Is () const
 Templated version for checking whether this value is type T.
Get () const
ValueTypeSet (const T &data)
bool Accept (Handler &handler) const
 Generate events of this value to a Handler.
GenericValueoperator= (GenericValue &rhs) RAPIDJSON_NOEXCEPT
 Assignment with move semantics.
GenericValueCopyFrom (const GenericValue< Encoding, SourceAllocator > &rhs, RAPIDJSON_DEFAULT_ALLOCATOR &allocator, bool copyConstStrings=false)
 Deep-copy assignment from Value.
GenericValueSwap (GenericValue &other) RAPIDJSON_NOEXCEPT
 Exchange the contents of this value with those of other.
GenericValueMove () RAPIDJSON_NOEXCEPT
 Prepare Value for move semantics.

Friends

template<typename, typename>
class GenericValue
void swap (GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
 free-standing swap function helper

Detailed Description

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
class rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >

A document for parsing JSON text as DOM.

Note
implements Handler concept
Template Parameters
EncodingEncoding for both parsing and string storage.
AllocatorAllocator for allocating memory for the DOM
StackAllocatorAllocator for allocating memory for stack during parsing.
Warning
Although GenericDocument inherits from GenericValue, the API does not provide any virtual functions, especially no virtual destructor. To avoid memory leaks, do not delete a GenericDocument object via a pointer to a GenericValue.

Constructor & Destructor Documentation

◆ GenericDocument() [1/2]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::GenericDocument ( Type type,
Allocator * allocator = 0,
size_t stackCapacity = kDefaultStackCapacity,
StackAllocator * stackAllocator = 0 )
inlineexplicit

Constructor.

Creates an empty document of specified type.

Parameters
typeMandatory type of object to create.
allocatorOptional allocator for allocating memory.
stackCapacityOptional initial capacity of stack in bytes.
stackAllocatorOptional allocator for allocating memory for stack.

◆ GenericDocument() [2/2]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::GenericDocument ( Allocator * allocator = 0,
size_t stackCapacity = kDefaultStackCapacity,
StackAllocator * stackAllocator = 0 )
inline

Constructor.

Creates an empty document which type is Null.

Parameters
allocatorOptional allocator for allocating memory.
stackCapacityOptional initial capacity of stack in bytes.
stackAllocatorOptional allocator for allocating memory for stack.

Member Function Documentation

◆ operator ParseResult()

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::operator ParseResult ( ) const
inline

Implicit conversion to get the last parse result.

Returns
ParseResult of the last parse operation
ParseResult ok = doc.Parse(json);
if (!ok)
printf( "JSON parse error: %s (%u)\n", GetParseError_En(ok.Code()), ok.Offset());
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition document.h:2709
ParseErrorCode Code() const
Get the error code.
Definition error.h:116
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition error.h:118
const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Definition en.h:36
Result of parsing (wraps ParseErrorCode)
Definition error.h:106
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition document.h:2890

◆ Parse() [1/3]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<unsigned parseFlags>
GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Parse ( const Ch * str)
inline

Parse JSON text from a read-only string.

Template Parameters
parseFlagsCombination of ParseFlag (must not contain kParseInsituFlag).
Parameters
strRead-only zero-terminated string to be parsed.

◆ Parse() [2/3]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Parse ( const Ch * str)
inline

Parse JSON text from a read-only string (with kParseDefaultFlags)

Parameters
strRead-only zero-terminated string to be parsed.

◆ Parse() [3/3]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<unsigned parseFlags, typename SourceEncoding>
GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Parse ( const typename SourceEncoding::Ch * str)
inline

Parse JSON text from a read-only string (with Encoding conversion)

Template Parameters
parseFlagsCombination of ParseFlag (must not contain kParseInsituFlag).
SourceEncodingTranscoding from input Encoding
Parameters
strRead-only zero-terminated string to be parsed.

◆ ParseInsitu() [1/2]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<unsigned parseFlags>
GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseInsitu ( Ch * str)
inline

Parse JSON text from a mutable string.

Template Parameters
parseFlagsCombination of ParseFlag.
Parameters
strMutable zero-terminated string to be parsed.
Returns
The document itself for fluent API.

◆ ParseInsitu() [2/2]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseInsitu ( Ch * str)
inline

Parse JSON text from a mutable string (with kParseDefaultFlags)

Parameters
strMutable zero-terminated string to be parsed.
Returns
The document itself for fluent API.

◆ ParseStream() [1/3]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<unsigned parseFlags, typename SourceEncoding, typename InputStream>
GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseStream ( InputStream & is)
inline

Parse JSON text from an input stream (with Encoding conversion)

Template Parameters
parseFlagsCombination of ParseFlag.
SourceEncodingEncoding of input stream
InputStreamType of input stream, implementing Stream concept
Parameters
isInput stream to be parsed.
Returns
The document itself for fluent API.

◆ ParseStream() [2/3]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<unsigned parseFlags, typename InputStream>
GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseStream ( InputStream & is)
inline

Parse JSON text from an input stream.

Template Parameters
parseFlagsCombination of ParseFlag.
InputStreamType of input stream, implementing Stream concept
Parameters
isInput stream to be parsed.
Returns
The document itself for fluent API.

◆ ParseStream() [3/3]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<typename InputStream>
GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::ParseStream ( InputStream & is)
inline

Parse JSON text from an input stream (with kParseDefaultFlags)

Template Parameters
InputStreamType of input stream, implementing Stream concept
Parameters
isInput stream to be parsed.
Returns
The document itself for fluent API.

◆ Populate()

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
template<typename Generator>
GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Populate ( Generator & g)
inline

Populate this document by a generator which produces SAX events.

Template Parameters
GeneratorA functor with bool f(Handler) prototype.
Parameters
gGenerator functor which sends SAX events to the parameter.
Returns
The document itself for fluent API.

◆ Swap() [1/2]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
GenericDocument & rapidjson::GenericDocument< Encoding, Allocator, StackAllocator >::Swap ( GenericDocument< Encoding, Allocator, StackAllocator > & rhs)
inline

Exchange the contents of this document with those of another.

Parameters
rhsAnother document.
Note
Constant complexity.
See also
GenericValue::Swap

◆ Swap() [2/2]

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
GenericValue & rapidjson::GenericValue< Encoding, Allocator >::Swap ( GenericValue & other)
inline

Exchange the contents of this value with those of other.

Parameters
otherAnother value.
Note
Constant complexity.

◆ swap

template<typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR, typename StackAllocator = RAPIDJSON_DEFAULT_STACK_ALLOCATOR>
void swap ( GenericDocument< Encoding, Allocator, StackAllocator > & a,
GenericDocument< Encoding, Allocator, StackAllocator > & b )
friend

free-standing swap function helper

Helper function to enable support for common swap implementation pattern based on std::swap:

void swap(MyClass& a, MyClass& b) {
using std::swap;
swap(a.doc, b.doc);
// ...
}
friend void swap(GenericDocument &a, GenericDocument &b) RAPIDJSON_NOEXCEPT
free-standing swap function helper
Definition document.h:2615
See also
Swap()

The documentation for this class was generated from the following file: